package day_2022_12_to_3.day;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/12/10 18:50
 **/
public class Day12_10_Num1961 {
    class Solution {
        public int maxHeight(int[][] cuboids) {
            int n=cuboids.length;
            for(int i=0;i<n;i++){Arrays.sort(cuboids[i]);}
            Arrays.sort(cuboids,(a, b)->a[0]==b[0]?(a[1]==b[1]?b[2]-a[2]:b[1]-a[1]):b[0]-a[0]);
            int h[]=new int[n];
            for(int i=0;i<n;i++){
                for(int j=0;j<i;j++){if(cuboids[j][1]>=cuboids[i][1]&&cuboids[j][2]>=cuboids[i][2]){h[i]=Math.max(h[i],h[j]);}}
                h[i]+=cuboids[i][2];
            }
            int ans=0;
            for(int i=0;i<n;i++){ans=Math.max(ans,h[i]);}
            return ans;
        }
    }
}